#!/bin/bash

# 确保脚本在出错时停止执行
set -e

# 需要修改为您的Docker Hub用户名 (不能包含@符号)
DOCKER_USERNAME="tommyi"
# 镜像名称
IMAGE_NAME="linghang-backend"
# 版本标签
VERSION="1.0.0"

# 确保已经Maven打包
echo "执行Maven打包..."
./mvnw clean package -DskipTests

# 设置Docker BuildX
echo "设置Docker BuildX..."
docker buildx create --use --name multiarch-builder || echo "BuildX已存在，跳过创建"
docker buildx inspect --bootstrap

# 构建并推送多架构镜像
echo "构建并推送多架构Docker镜像..."
docker buildx build --platform linux/amd64,linux/arm64 \
  -t $DOCKER_USERNAME/$IMAGE_NAME:$VERSION \
  -t $DOCKER_USERNAME/$IMAGE_NAME:latest \
  --push .

echo "多架构镜像已成功构建并推送到Docker Hub"
echo "镜像地址: https://hub.docker.com/r/$DOCKER_USERNAME/$IMAGE_NAME" 